package jehc.djshi.sys.web;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jehc.djshi.common.annotation.Auth;
import jehc.djshi.common.base.BaseAction;
import jehc.djshi.common.base.BaseResult;
import jehc.djshi.common.util.StringUtil;
import jehc.djshi.sys.model.XtCompany;
import jehc.djshi.sys.service.XtCompanyService;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * @Desc 公司信息
 * @Author 邓纯杰
 * @CreateTime 2012-12-12 12:12:12
 */
@RestController
@RequestMapping("/xtCompany")
@Api(value = "平台公司信息API",tags = "平台公司信息API",description = "平台公司信息API")
public class XtCompanyController extends BaseAction {

	@Resource
	private XtCompanyService xtCompanyService;

	/**
	 * 查询公司信息
	 * @return
	 */
	@ApiOperation(value="查询公司信息", notes="查询公司信息")
	@GetMapping(value="/get/singel")
	@Auth(value = "/xtCompany/get/singel",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	public BaseResult<XtCompany> getXtCompany(){
		Map<String, Object> condition = new HashMap<String, Object>();
		List<XtCompany> XtCompanyList = xtCompanyService.getXtCompanyListByCondition(condition);
		XtCompany xtCompany = new XtCompany();
		if(!XtCompanyList.isEmpty()){
			xtCompany = XtCompanyList.get(0);
		}
		return outDataStr(xtCompany);
	}

	/**
	 * 添加或修改
	 * @param xtCompany
	 */
	@ApiOperation(value="添加或修改公司信息", notes="添加或修改公司信息")
	@PostMapping(value="/addOrUpdate")
	public BaseResult addOrUpdateXtCompany(@RequestBody XtCompany xtCompany){
		int i = 0;
		if(null != xtCompany){
			if(!StringUtil.isEmpty(xtCompany.getId())){
				i = xtCompanyService.updateXtCompany(xtCompany);
			}else{
				xtCompany.setId(toUUID());
				i=xtCompanyService.addXtCompany(xtCompany);
			}
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}

	/**
	 * 删除
	 * @param id
	 */
	@ApiOperation(value="删除公司信息", notes="删除公司信息")
	@DeleteMapping(value="/delete")
	public BaseResult delXtCompany(String id){
		int i = 0;
		if(!StringUtil.isEmpty(id)){
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("id",id.split(","));
			i=xtCompanyService.delXtCompany(condition);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}
}
